<template>
    <!-- 对话框表单 -->
    <!-- 建议使用 Prettier 格式化代码 -->
    <!-- el-form 内可以混用 el-form-item、FormItem、ba-input 等输入组件 -->
    <el-dialog
        class="ba-operate-dialog"
        :close-on-click-modal="false"
        :model-value="modelValue" 
        :before-close="closeForm"
        width="50%"
    >
        <template #header>
            <div class="title" v-drag="['.ba-operate-dialog', '.el-dialog__header']" v-zoom="'.ba-operate-dialog'">
                {{ t('编辑') }}
            </div>
        </template>
        <el-scrollbar class="ba-table-form-scrollbar">
            <div
                class="ba-operate-form"
                :class="'ba-edit-form'"
                :style="'width: calc(100% - 100px)'"
            >
                <el-form
                    @submit.prevent=""
                    :model="state.form"
                    label-position="right"
                    label-width="180px"
                >
                    <FormItem
                        type="remoteSelect"
                        prop="pid"
                        :label="t('上级分类')"
                        v-model="state.form.pid"
                        :placeholder="t('请选择分类')"
                        :input-attr="{
                            params: { isTree: true },
                            field: 'name',
                            'remote-url': '/system/category.IndustryQcc/index',
                        }"
                    />
                    <FormItem :label="t('分类名称')" type="string" v-model="state.form.name" />
                    
                </el-form>
            </div>
        </el-scrollbar>
        <template #footer>
            <div :style="'width: calc(100% - 180px)'">
                <el-button @click="closeForm">{{ t('取消') }}</el-button>
                <el-button v-blur  @click="save()" type="primary">{{ t('保存') }}</el-button>
            </div>
        </template>
    </el-dialog>
</template>

<script setup lang="ts">
import { reactive, onMounted } from 'vue'
import { useI18n } from 'vue-i18n'
import FormItem from '/@/components/formItem/index.vue'

import { updateApi } from '/@/api/most/category/industry_qcc'


const { t } = useI18n()


const state = reactive({
    form: {
        id: 0,
        pid: 0,
        name: ''
    }
})

interface Props {
    modelValue: boolean
    configGroup: anyObj
    form: anyObj
}

const props = withDefaults(defineProps<Props>(), {
    modelValue: false,
    configGroup: () => {
        return {}
    },
})

const emit = defineEmits(["close", "refresh"])


const save = () => {
    updateApi(state.form).then((e) => {
        console.log(e)
        emit("refresh");
        closeForm()
    })
}

const closeForm = () => {
    emit("close")
}

onMounted(() => {
    state.form = props.form;
})

</script>

<style scoped lang="scss">
:deep(.el-upload-list--picture-card .el-upload-list__item){
    width: 90px;
    height: 90px;
}
:deep(.el-upload--picture-card){
    width: 90px;
    height: 90px;
}
:deep(.ba-upload-select-image){
    width: 90px;
}
:deep(.ba-upload.files .el-button [class*=el-icon]+span){
    position: relative;
    top: -3px;
}
</style>
